<template>
  <div class="home">
    <h1>插件测试</h1>
    <div>
      <button @click="openWPS">Wps插件测试</button>
      <button @click="authenticate">身份认证测试</button>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Plugins } from '@capacitor/core';
const { OAuthPlugin, WpsPlugin } = Plugins;

@Component({
  components: {
  },
})
export default class Home extends Vue {

  /** 
   * 权限token
   */
  private token = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJTUFBAZ3Vhbmd4aS5jb20iLCJleHAiOjE2NDc5NTYzNzUsImlhdCI6MTY0Nzk0OTE3NX0.hvnwBYklmf02KykyihDJWbNmdx9josmOClWUVtnv2EL_G-VyzpIkgWh2SRqfY5lU_HB0dgAe5bGOxjRDOEQA5VoJzMR0_-9pU687G_9F1-y8WxaurPN-ekzzKjsGuu65JSdPUtvtmTkDYtU1HqGGecwcW4XVj_4ABBFchyXZfKs";

  /** 
   * 基础路径
   */
  private baseUrl = "http://172.16.240.111:30802";

  /** 
   * wps打开
   */
  public openWPS(){
    let params = {
      downloadUrl: `${this.baseUrl}/net-disk/wpsdownload/doctemplate/220211_1491988068203409410/%E6%AD%A3%E6%96%87.wps?authcode=undefined&ibzuaa-token=Bearer ${this.token}&srfsystemid=OA`,
      uploadUrl: `${this.baseUrl}/net-disk/wpsupload/doctemplate/220211_1491988068203409410/%E6%AD%A3%E6%96%87.wps?ownertype=template&ownerid=2cb461b6-19da-c5f1-4aef-fad9a7ea9fa9&ibzuaa-token=Bearer ${this.token}&srfsystemid=OA`,
      filename: "cheshi.doc"
    }
    WpsPlugin.editAndSave(params).then((res: any)=>{
      alert("成功")
      alert(JSON.stringify(res))
    }).catch(()=>{
      alert("失败")
    })
  }

  /**
   * 吉大正元身份认证插件测试
   */
  public async authenticate(){
    let appID = "测试";
    let url = "htpps://www.baidu.com";
    try {
      const { OAuthPlugin } = Plugins;
      const res = await OAuthPlugin.authenticate({appID: appID, url: url});
      alert("成功"+JSON.stringify(res))
    } catch (error) {
      alert(error)
    }
  }

}
</script>
